<template>
    <div ref="city_wrap">
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list :cities="cities"  :hot="hotCites" :letter="letter"></city-list>
        <city-alphabet
                :cities="cities"
                @change="handleLetterChange"
                :city_wrap_height="city_wrap_height"
        ></city-alphabet>
    </div>
</template>

<script>
    import axios from 'axios'

    import CityHeader from './components/header'
    import CitySearch from './components/Search'
    import CityList from './components/list'
    import CityAlphabet from './components/Alphabet'
    export default {
        name: "city",
        components:{
            CityHeader,
            CitySearch,
            CityList,
            CityAlphabet
        },
        data () {
            return {
                cities:{},
                hotCites:[],
                letter:{},
                city_wrap_height:0
            }
        },
        // 这里用created也可以，但是还是建议大家用mounted
        mounted () {
            this.getCityInfo();
            this.city_wrap_height=this.$refs.city_wrap.clientHeight;
        },
        methods:{
            getCityInfo () {
                axios.get('/api/city.json')
                    .then(this.handleGetCityInfoSucc)
            },
            handleGetCityInfoSucc ( res ) {
                // console.log(res)
                res=res.data
                if(res.ret&&res.data){
                    const data=res.data
                    this.cities=data.cities
                    this.hotCites=data.hotCities
                }
            },
            handleLetterChange (letter){
                // console.log(letter);
                this.letter=letter;
            }
        }
    }
</script>

<style lang="stylus" scoped>

</style>